package nowcoder;

/**
 * @author tuyou_cd
 * @date 2021/4/29 16:07
 */
public class 最长上升子序列 {

    /**
     * 动态规划法
     * @param A
     * @return
     */
    public static int getMaxAscStr(final int[] A) {
        //dp数组，位置i存储的是以A[i]为最大的值升序长度
        int[] maxArr = new int[A.length];
        for (int i = 0; i < A.length; i++) {
            maxArr[i] = 1;
            for (int j = 0; j < i; j++) {
                if (A[j] < A[i] && maxArr[j] + 1 > maxArr[i]) {
                    maxArr[i] = maxArr[j] + 1;
                }
            }
        }

        int maxLength = 1;
        for (int i = 0; i < maxArr.length; i++) {
            if (maxArr[i] > maxLength) {
                maxLength = maxArr[i];
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        int[] arr = {2,5,3,4,1,7,6};
        System.out.println(getMaxAscStr(arr));
    }
}
